//
//  MoBanTwoViewController.m
//  MoBan
//
//  Created by apple on 16/7/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "MoBanTwoViewController.h"
#import "MoBanCellCollection.h"
#import "ZBTableCell.h"
#import "MoBanUnit.h"
#import "selectView.h"
@interface MoBanTwoViewController ()<UITableViewDataSource,UITableViewDelegate,selectViewDeleget,MoBanCellCollectionDeleget>
@property(nonatomic,strong)UITableView *tableview;
@property(nonatomic,strong)NSMutableArray *array;
@end

@implementation MoBanTwoViewController
//该数组是把所有的请求来的数据的数组存放到里面
#warning 这个数组里面必须放四个数组，如果数组不够的的话要用空数组占位
-(NSMutableArray *)array
{
    if (!_array) {
        _array = [NSMutableArray array];
    }
    return _array;
}
-(UITableView *)tableview
{
    if (!_tableview) {
        _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KscrW, KscrH-KBar1)];
        _tableview.dataSource = self;
        _tableview.delegate = self;
    }
    return _tableview;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableArray *array0 = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"4",@"5", nil];
    NSMutableArray *array1 = [NSMutableArray arrayWithObjects:@"1",@"2",@"3", nil];
    NSMutableArray *array2 = [NSMutableArray arrayWithObjects:@"2", nil];
    NSMutableArray *array3 = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
    
    [self.array addObject:array0];
    [self.array addObject:array1];
    [self.array addObject:array2];
    [self.array addObject:array3];
    
    [self.view addSubview:self.tableview];
    
    // Do any additional setup after loading the view.
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}// Default is 1 if not implemented

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return   [MoBanUnit ZBRowAtIndexpathSection:section WithArray:self.array];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section<3) {
        NSString *str = [MoBanUnit ZBTableviewReuserIndentAtIndexSection:indexPath.section];
        
        MoBanCellCollection *cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (!cell) {
            cell = [[MoBanCellCollection alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
        }
        cell.deleget = self;
        [cell ZBSetCollectionViewWithArray:self.array[indexPath.section]];
        return cell;

    }
    
    ZBTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZBTableCell"];
    
    if (!cell) {
        cell= [[ZBTableCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ZBTableCell"];
    }
    [  cell ZBSetDatasouceWithModel:self.array[indexPath.section][indexPath.row] ];
    return cell;
    

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
  return   [MoBanUnit ZBTableViewHeadHightInSection:section];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return [MoBanUnit ZBTableViewFotterHightInSection:section];
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [MoBanUnit ZBtableviewCellHightInSection:indexPath.section WithArray:self.array];
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section==3) {
        selectView *select= [[selectView alloc]init];
        select.frame = CGRectMake(0, 0, KscrW, 40*Kscr);
        select.deleget = self;
        [select gaveMestringArray:@[@"测试1",@"测试2",@"测试3"]];
        return select;
    }
    
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [ZBProssHud showsuccessFrom:self.view with:[NSString stringWithFormat:@"%ld",indexPath.row]];

}
-(void)btnClic:(selectButten *)btn
{
    [ZBProssHud showsuccessFrom:self.view with:[NSString stringWithFormat:@"%ld",btn.tag]];
}
-(void)ZBMobancellectionview:(UICollectionView *)collection DidselectdeAtindex:(NSInteger)inter;
{
[ZBProssHud showsuccessFrom:self.view with:[NSString stringWithFormat:@"点击了%@%ld个cell",collection.restorationIdentifier,inter]];
}
@end
